package com.leetcode.BinaryTree;

//翻转二叉树
public class lc_226 {
    public static void main(String[] args) {

    }

    public TreeNode invertTree(TreeNode root){
        //思路: 对于每一棵左右子树,直接进行翻转
        //1.边界条件:root==null,return root;
        if(root == null){
            return null;
        }
        //2.每一层逻辑,交换左右子树
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }
}
